This script randomly chooses a number between one and a hundred. The player guesses at the number and is given hints.I am thinking of a number from 1 to 100. Can you guess what it is?
The script sets the focus to the input field when the page loads by including
onLoad="document.forms[0].guess.focus()"in the initial body tag. This means that the game can be played right away without clicking on the "guess" text input field.
Note: Because a player might enter text rather than a number, guess updates the guess box to a parseInt() function call. If a player typed an invalid text string, rather than a number, the guess box shows "NaN". Netscape treats this nonnumber as a zero, more or less. (Netscape Navigator version 3.0 will permit scripts to test for "NaN".)
var num = parseInt(thisform.guess.value) thisform.guess.value = num